package com.tappytaps.android.hc2010;

import java.util.Locale;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.google.api.translate.Language;
import com.tappytaps.android.hc2010.helper.TranslatorHelper;


public class VocabularyActivity extends VoiceRecognitionActivity {
	
	Button btnTranslate;
	Button btnGetVoice;
	EditText edToTranslate;
	TextView txtResult;
	
	TranslatorHelper translatorHelper;
	
	
	   @Override
	    public void onCreate(Bundle savedInstanceState) {
	    	super.onCreate(savedInstanceState);
	        setContentView(R.layout.vocabulary_activity);
	        btnTranslate = (Button)findViewById(R.id.btnTranslate);
	        btnGetVoice = (Button)findViewById(R.id.btnGetVoice);
	        edToTranslate = (EditText)findViewById(R.id.edToTranslate);
	        txtResult = (TextView)findViewById(R.id.txtResult);
	        translatorHelper = new TranslatorHelper(Language.ENGLISH, Language.CZECH, this);
	        btnTranslate.setOnClickListener(new OnClickListener() {				
				public void onClick(View v) {
				    String translatedText = null;
					translatedText = translatorHelper.translateFromSource(edToTranslate.getText().toString());
					txtResult.setText(translatedText);
					translatorHelper.sayInDestination(translatedText);
				}
			});
	        btnGetVoice.setOnClickListener(new OnClickListener() {				
				public void onClick(View v) {
					startVoiceRecognitionActivity("Say something..." ,"en");
				}
			});
	    }
	   
	   
	   // MENU
	   @Override
	   public boolean onCreateOptionsMenu(Menu menu) {
	       MenuInflater inflater = getMenuInflater();
	       inflater.inflate(R.menu.vocabulary_menu, menu);
	       return true;
	   }
	   
	   
	   @Override
	   public boolean onOptionsItemSelected(MenuItem item) {
	       // Handle item selection
	       switch (item.getItemId()) {
	       case R.id.add_item:
	           // TODO
	           return true;
	       default:
	           return super.onOptionsItemSelected(item);
	       }
	   }

	@Override
	void voiceRecognized(String s) {
		edToTranslate.setText(s);
	}
}
